/* sockets_plarform.h */

/************************************************************************************
*                    Copyright Aquantia Corporation
*                              Freeware
*
* Description:
*
*   This file contains socket library adaptation for POSIX and WinSock. The platform
*   integrator must provide these definitions if another socket library is used.
*
************************************************************************************/

/*! \file
    This file contains socket library adaptation for POSIX and WinSock. The platform
    integrator must provide these definitions if another socket library is used.
*/

#ifndef AQ_SOCKETS_PLATFORM_TOKEN
#define AQ_SOCKETS_PLATFORM_TOKEN


#if defined (WIN32) || defined (X64)
  #define USE_WINSOCK
#endif

#ifdef USE_WINSOCK
  #include <winsock2.h>
  #include <ws2tcpip.h>
#else
  #include <sys/socket.h>
  #include <sys/select.h>
  #include <sys/types.h>
  
  /* define __USE_GNU so that ip_mreq is defined in subsequent versions of ip_mreq */
  #define __USE_GNU
  #include <netinet/ip.h>
  #undef __USE_GNU
  
  #include <netinet/tcp.h>
  #include <unistd.h>
  #include <arpa/inet.h>
  #include <netdb.h>
#endif

/*! \addtogroup Sockets Socket Library
  @{*/

#ifdef USE_WINSOCK
  /*! Define socklen_t type (Windows uses int for this) */
  typedef int socklen_t;

  /*! Definition for socket close function. Windows uses closesocket() */
  #define CLOSE closesocket
  
  /*! Converts IP address from text to numeric form.
      Windows didn't support this function until Vista */
  int Windows_inet_pton (int af, const char *src, void *dst);
  
  /*! Definition for inet_pton function. Use local version */
  #define INET_PTON Windows_inet_pton
#else
  /*! Define SOCKET type for compatibility with WinSock */
  typedef int SOCKET;
  /*! Define INVALID_SOCKET for compatibility with WinSock */
  #define INVALID_SOCKET  -1

  /*! Definition for socket close function. Use common close() */
  #define CLOSE close

  /*! Definition for inet_pton function. Use standard version */
  #define INET_PTON inet_pton
#endif

/*@}*/

#endif